package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TTransactionDetailMapper;

import javax.annotation.Resource;

/**
 * 收入、支出、转移的明细列Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-03-17
 */
@Service
public class TTransactionDetailServiceImpl implements ITTransactionDetailService 
{
    @Autowired
    private TTransactionDetailMapper tTransactionDetailMapper;

    @Resource
    private ITReasonService itReasonService;

    @Resource
    private ITAccountService itAccountService;

    @Resource
    private ITCurrencyService itCurrencyService;

    @Resource
    private ITCompanyService itCompanyService;

    /**
     * 查询收入、支出、转移的明细列
     * 
     * @param tid 收入、支出、转移的明细列主键
     * @return 收入、支出、转移的明细列
     */
    @Override
    public TTransactionDetail selectTTransactionDetailByTid(Long tid)
    {
        return tTransactionDetailMapper.selectTTransactionDetailByTid(tid);
    }

    /**
     * 查询收入、支出、转移的明细列列表
     * 
     * @param tTransactionDetail 收入、支出、转移的明细列
     * @return 收入、支出、转移的明细列
     */
    @Override
    public List<TTransactionDetail> selectTTransactionDetailList(TTransactionDetail tTransactionDetail)
    {
        List<TTransactionDetail> tTransactionDetails=tTransactionDetailMapper.selectTTransactionDetailList(tTransactionDetail);
        for(TTransactionDetail i : tTransactionDetails){
            if(i.getOfAccount()!=null){
                TAccount tAccount=itAccountService.selectTAccountByAid(i.getOfAccount());
                i.setAccountName(tAccount.getAname());
            }
            if(i.getOfReason()!=null){
                TReason tReason=itReasonService.selectTReasonByRid(i.getOfReason());
                i.setReasonName(tReason.getRname());
            }
            if(i.getOfCurrency()!=null){
                TCurrency tCurrency=itCurrencyService.selectTCurrencyByCid(i.getOfCurrency());
                i.setCeName(tCurrency.getCnName()+"("+tCurrency.getEnName()+")");
            }
            if(i.getOfCompany()!=null){
                TCompany tCompany=itCompanyService.selectTCompanyById(i.getOfCompany());
                i.setCompanyName(tCompany.getCompanyName());
            }
        }

        return tTransactionDetails;
    }

    @Override
    public List<TTransactionDetail> selectTTransactionDetaiE(TTransactionDetail tTransactionDetail) {
        return tTransactionDetailMapper.selectTTransactionDetaiE(tTransactionDetail);
    }

    /**
     * 新增收入、支出、转移的明细列
     * 
     * @param tTransactionDetail 收入、支出、转移的明细列
     * @return 结果
     */
    @Override
    public int insertTTransactionDetail(TTransactionDetail tTransactionDetail)
    {
        return tTransactionDetailMapper.insertTTransactionDetail(tTransactionDetail);
    }

    /**
     * 修改收入、支出、转移的明细列
     * 
     * @param tTransactionDetail 收入、支出、转移的明细列
     * @return 结果
     */
    @Override
    public int updateTTransactionDetail(TTransactionDetail tTransactionDetail)
    {
        return tTransactionDetailMapper.updateTTransactionDetail(tTransactionDetail);
    }

    /**
     * 批量删除收入、支出、转移的明细列
     * 
     * @param tids 需要删除的收入、支出、转移的明细列主键
     * @return 结果
     */
    @Override
    public int deleteTTransactionDetailByTids(Long[] tids)
    {
        return tTransactionDetailMapper.deleteTTransactionDetailByTids(tids);
    }

    /**
     * 删除收入、支出、转移的明细列信息
     * 
     * @param tid 收入、支出、转移的明细列主键
     * @return 结果
     */
    @Override
    public int deleteTTransactionDetailByTid(Long tid)
    {
        return tTransactionDetailMapper.deleteTTransactionDetailByTid(tid);
    }
}
